﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Supermarket.Bll;

namespace Supermarket.Web.CashierPages
{
    public partial class CheckOutSupply : System.Web.UI.Page
    {
        private string CartId { get; set; }
        private decimal totalSum = 0m;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Supermarket_CartID"] == null)
            {
                Session["Supermarket_CartID"] = Membership.GetUser().ProviderUserKey.ToString();
            }

            CartId = Session["Supermarket_CartID"].ToString();
            ShoppingCartManager.CardId = CartId;
        }

        protected void GridViewCheckedProducts_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                totalSum += decimal.Parse(e.Row.Cells[3].Text);
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[3].Text = String.Format("Общо: {0:0.00} лв.", totalSum);
            }
        }

        protected void ButtonCheckOut_Click(object sender, EventArgs e)
        {
            ButtonCheckOut.Visible = false;
            LabelResult.Text = ShoppingCartManager.CheckOutSupply(CartId);
        }
    }
}